/*
 * @Date: 2020-08-23 21:18:25
 * @LastEditors: 小枫
 * @LastEditTime: 2020-09-17 11:05:02
 * @FilePath: \feng-blog\config\config.default.ts
 */
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1598188681969_5541';

  // add your egg config in here
  config.middleware = [];

  config.mysql = {
    client: { // 单数据库信息配置
      host: 'localhost', // host
      port: '3306', // 端口号
      user: 'liuhao', // 用户名
      password: '123456', // 密码
      database: 'feng-blog', // 数据库名
    },
    app: true, // 是否加载到 app 上，默认开启
    agent: false, // 是否加载到 agent 上，默认关闭
  };

  // JWT秘钥
  config.jwt = {
    secret: 'xiaofeng',
  };

  // validate, 参数校验器
  config.validate = {
    convert: true, // 对参数可以使用convertType规则进行类型转换
    // validateRoot: false,   // 限制被验证值必须是一个对象。
  };

  // 关闭csrf
  config.security = {
    csrf: {
      enable: false, // 关闭csrf
    },
    domainWhiteList: [ '*' ], // 白名单
  };

  // CORS
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
